package com.bgs.service.impl;

import com.bgs.common.R;
import com.bgs.feign.ZeroFeign;
import com.bgs.feign.ZeroFeign1;
import com.bgs.pojo.vo.BeforeUser;
import com.bgs.pojo.vo.OrderDetail;
import com.bgs.pojo.ReturnGoods;
import com.bgs.mapper.ReturnGoodsMapper;
import com.bgs.pojo.vo.Store;
import com.bgs.service.ReturnGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 退货表 服务实现类
 * </p>
 *
 * @author Asia
 * @since 2021-09-14
 */
@Service
public class ReturnGoodsServiceImpl extends ServiceImpl<ReturnGoodsMapper, ReturnGoods> implements ReturnGoodsService {
    @Resource
    private ReturnGoodsMapper returnGoodsMapper;
    @Autowired
    private ZeroFeign zeroFeign;
    @Autowired
    private ZeroFeign1 zeroFeign1;

    @Override
    public List<ReturnGoods> TowGetReturn(Integer beforeUserId) {
        return returnGoodsMapper.TowGetReturn();
    }

    @Override
    public boolean zeroAddReturnGood(ReturnGoods returnGoods) {
        return returnGoodsMapper.zeroAddReturnGood(returnGoods);
    }

    @Override
    public R zeroFindReturnGood3() {
        List<ReturnGoods> list = returnGoodsMapper.zeroFindReturnGood3();
        return R.ok().data("zeroFindReturnGood3", list);
    }

    @Override
    public boolean zeroUpdateReturnGood0(Integer returnGoodsId) {
        return returnGoodsMapper.zeroUpdateReturnGood0(returnGoodsId);
    }

    @Override
    public boolean zeroAddshipping(ReturnGoods returnGoods) {
        return returnGoodsMapper.zeroAddshipping(returnGoods);
    }

    @Override
    public boolean zeroUpdateReturnGood1(ReturnGoods returnGood) {
        //扣款操作
        //通过商品id找到商户id，进行扣款
        List<OrderDetail> orderDetails = zeroFeign1.zeroOrderDetailIdToOrderDetail(returnGood.getOrderDetailId());

        List<Store> stores = zeroFeign.zeroStoreIdToStore(orderDetails.get(0).getStoreId());

        List<BeforeUser> beforeUsers = zeroFeign.zeroBeforeUserIdToBeforeUser(stores.get(0).getBeforeUserId());
        //输出结果：余额100
        System.out.println("余额" + beforeUsers.get(0).getBalance());
        //店家用户id and 退款金额
        boolean b = zeroFeign.zeroReturnGoodsSubtractBalance(beforeUsers.get(0).getBeforeUserId(), returnGood.getReturnGoodsPayment());

        //修改状态为1
        return returnGoodsMapper.zeroUpdateReturnGood1(returnGood.getReturnGoodsId());
    }

    @Override
    public int TowReturnAdd(ReturnGoods returnGoods) {
        return returnGoodsMapper.TowReturnAdd(returnGoods);
    }

//    @Override
//    public R zeroGetToReportList(ZeroToReportAndOrderDetail zeroToReportAndOrderDetail) {
//        List<ZeroToReportAndOrderDetail> zeroToReportAndOrderDetails=toReportMapper.zeroGetToReportList(zeroToReportAndOrderDetail);
//
//        //获取商品id，用来查询店铺，或获取商品，再另一个服务循环
////        zeroToReportAndOrderDetail.getOrderDetail().getStoreId();
//        R r= zeroFeign.zeroGetStoreToZeroToReportAndOrderDetail(zeroToReportAndOrderDetails);
//
////        return R.ok().data("zeroToReportAndOrderDetails",zeroToReportAndOrderDetails);
//        return r;
//    }

}
